<?php

namespace app\command;

use app\admin\model\Config;
use app\model\DistributionSetting;
use app\model\Order;
use app\model\Talent;
use app\model\User;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use util\Logger;
use Wechat\CommerceApp;

class FixOrderProfitCommand extends Command
{
    protected function configure()
    {
        $this->setName('fix-order-profit')
            ->setDescription('修复订单利润');
    }

    protected function execute(Input $input, Output $output)
    {
        Order::field('id, actual_commission, commission, agent_commission')
            ->chunk(50, function ($orders) {
                $save = [];
                foreach ($orders as $order) {
                    $profit = $order['actual_commission'] - $order['commission'] - $order['agent_commission'];
                    $save[] = [
                        'id'     => $order['id'],
                        'profit' => $profit,
                    ];
                }
                if ($save) {
                    (new Order())->saveAll($save);
                }
            });

    }
}
